<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="dist/behaviorTree.js"></script>
</head>
<body>
    <script>
        let data = {"version":"0.3.0","scope":"tree","id":"e5c9cf1e-da6e-43e4-8362-433a231fa87c","title":"A behavior tree","description":"","root":"10b1589b-b9ce-4566-aeab-1f679dd3fee8","properties":{},"nodes":{"b91b5a10-9c68-4bf8-9652-4cd01a7caa55":{"id":"b91b5a10-9c68-4bf8-9652-4cd01a7caa55","name":"Logger","title":"输出","description":"输出内容","properties":{"msg":"Hello"},"display":{"x":0,"y":-60}},"5af74657-5f69-4fd9-8488-295f741ac534":{"id":"5af74657-5f69-4fd9-8488-295f741ac534","name":"Logger","title":"输出","description":"输出内容","properties":{"msg":"World"},"display":{"x":0,"y":0}},"fe6a1d37-ed7e-4df2-88bd-44d674e0ff3b":{"id":"fe6a1d37-ed7e-4df2-88bd-44d674e0ff3b","name":"Wait","title":"Wait <milliseconds>ms","description":"","properties":{"milliseconds":2000},"display":{"x":0,"y":-180}},"ba1c37bf-7ca3-47f2-bcf6-f6316ed100dd":{"id":"ba1c37bf-7ca3-47f2-bcf6-f6316ed100dd","name":"Succeeder","title":"Succeeder","description":"","properties":{},"display":{"x":0,"y":60}},"10b1589b-b9ce-4566-aeab-1f679dd3fee8":{"id":"10b1589b-b9ce-4566-aeab-1f679dd3fee8","name":"MemSequence","title":"MemSequence","description":"","properties":{},"display":{"x":-240,"y":-12},"children":["fe6a1d37-ed7e-4df2-88bd-44d674e0ff3b","3b43c8e0-4cc8-485c-a354-6747e17010c1","b91b5a10-9c68-4bf8-9652-4cd01a7caa55","5af74657-5f69-4fd9-8488-295f741ac534","ba1c37bf-7ca3-47f2-bcf6-f6316ed100dd"]},"3b43c8e0-4cc8-485c-a354-6747e17010c1":{"id":"3b43c8e0-4cc8-485c-a354-6747e17010c1","name":"randomPercent","title":"随机百分百","description":"","properties":{"percent":50},"display":{"x":36,"y":-120}}},"display":{"camera_x":960,"camera_y":468.5,"camera_z":1,"x":-372,"y":-12},"custom_nodes":[{"version":"0.3.0","scope":"node","name":"Logger","category":"action","title":"输出","description":"输出内容","properties":{}},{"version":"0.3.0","scope":"node","name":"randomPercent","category":"condition","title":"随机百分百","description":null,"properties":{"percent":50}}]};
        class RandomPercent extends bt.Condition {
            constructor(params){
                super(params);
                this.name = 'Logger';
            }
            
            tick(tick) {
                if (Math.random() * 100 > this.properties.percent) {
                    console.log('随机成功');
                    return bt.ActionStatus.SUCCESS;
                }
                console.log('随机失败');
                return bt.ActionStatus.FAILURE;
            }
        }
        let tree = new bt.BehaviorTree();
        tree.load(data, {
            randomPercent: RandomPercent
        });
        let blackboard = new bt.Blackboard();
        let obj = {};
        setInterval(() => {
            tree.tick(obj, blackboard);
        }, 100);

    </script>
</body>
</html>